﻿using System;

namespace BitButterECS.System
{
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
	public class UpdateIntervalAttribute : Attribute
	{
		public UpdateIntervalAttribute(float interval)
		{
			Interval = interval;
		}

		public float Interval { get; }

		public static float GetResolutionInterval(object system)
		{
			var attrs = system.GetType().GetCustomAttributes(typeof(UpdateIntervalAttribute), true);
			if (attrs.Length > 0)
			{
				var attr = attrs[0] as UpdateIntervalAttribute;
				if (attr != null)
				{
					return attr.Interval;
				}
			}
			return -1;
		}
	}
}
